<template>
  <div class="logout-container">
    <h1>账户管理</h1>
    <div class="logout-content">
      <p>您确定要注销当前账户吗？</p>
      <button class="logout-button" @click="handleLogout" :disabled="isLoading">
        {{ isLoading ? '注销中...' : '确认注销' }}
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const isLoading = ref(false);

const handleLogout = async () => {
  try {
    isLoading.value = true;
    
    // 清除登录状态
    localStorage.removeItem('isLoggedIn');
    localStorage.removeItem('username');
    localStorage.removeItem('loginTime');
    localStorage.removeItem('requestUuid');
    
    // 可选：添加短暂延迟以显示注销中状态
    await new Promise(resolve => setTimeout(resolve, 500));
    
    // 重定向到登录页面
    router.push('/login');
  } catch (error) {
    console.error('Logout error:', error);
    // 在实际应用中可能需要添加错误提示
  } finally {
    isLoading.value = false;
  }
};
</script>

<style scoped>
.logout-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 20px;
}

.logout-content {
  background: white;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  text-align: center;
  width: 100%;
  max-width: 400px;
}

.logout-content h1 {
  margin-bottom: 20px;
  color: #333;
}

.logout-content p {
  margin-bottom: 30px;
  color: #666;
  font-size: 16px;
}

.logout-button {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.logout-button:hover:not(:disabled) {
  background-color: #c82333;
}

.logout-button:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
}
</style>